from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.


class UserImage(models.Model):
    image = models.ImageField(verbose_name='用户头像', width_field=40, height_field=40)


class UserProvince(models.Model):
    province = models.CharField(max_length=20, verbose_name='省份')


class UserCity(models.Model):
    city = models.CharField(max_length=30, verbose_name='城市')
    province = models.ForeignKey(UserProvince, verbose_name='关联省份')

class UserInfo(AbstractUser):
    '''
    用户信息表
    '''

    GENDER = (
        ('1', '男'),
        ('2', '女'),
        ('3', '保密'),
    )

    username = models.CharField(max_length=20, verbose_name='昵称', unique=True)
    introduce = models.TextField(max_length=144, verbose_name='介绍', blank=True, null=True)
    gender = models.CharField(max_length=1, verbose_name='性别', choices=GENDER)
    # birthday = models.DateTimeField(verbose_name='生日', blank=True, null=True)
    image = models.ForeignKey(UserImage, verbose_name='用户头像', null=True)
    province = models.ForeignKey(UserProvince, verbose_name='省份', null=True)
    city = models.ForeignKey(UserCity, verbose_name='城市', related_name='user_city', null=True)
    email = models.EmailField(verbose_name='邮箱', unique=True)
    captcha = models.CharField(max_length=6, verbose_name='验证码')
    password = models.CharField(max_length=16, verbose_name='密码')

class UserCaptcha(models.Model):
    captcha = models.CharField(max_length=6, verbose_name='验证码')
    email = models.EmailField(verbose_name='邮箱')
    add_time = models.DateTimeField(auto_now=True, verbose_name='添加时间')

    class Meta:
        verbose_name = '用户注册验证码'
        verbose_name_plural = verbose_name




